package com.ptszyxx.popose.common.weiget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.YVoiceUtil;

/**
 * 语音
 */
public class VoiceView extends LinearLayout {
    private View parent;
    private ImageView ivPlay, ivVoice;
    private TextView tvVoiceLength;

    private String voiceUrl;

    public VoiceView(Context context) {
        super(context);
    }

    public VoiceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        View view = View.inflate(context, R.layout.widget_voice, this);
        parent = view.findViewById(R.id.parent);
        ivPlay = view.findViewById(R.id.ivPlay);
        ivVoice = view.findViewById(R.id.ivVoice);
        tvVoiceLength = view.findViewById(R.id.tvVoiceLength);

        initListener();
    }

    private void initListener() {
        parent.setOnClickListener(view -> {
            YVoiceUtil.getInstance().startPlay(ivVoice, voiceUrl);
        });
    }

    public void setData(String voiceUrl, String voiceTime){
        this.voiceUrl = voiceUrl;

        tvVoiceLength.setText(voiceTime + "s''");
    }









}
